<template>
  <div id="findClinic">
    <header>
      <i @click="goBack()"></i>
      <div>寻找诊室</div>
    </header>
    <div>
      <div id="searchResultPanel"></div>
      <div id='allmap'></div>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        id: '',
        status: '',
        doctorname: '',
        letter: '',
        inputVal: '',
        showX: false,
        // isFocus: true,  //是否可以聚焦于表单 默认是 当搜索完后否
        user: '',
        pointArr: [], //标记点诊室
        iconImg: require('../../../image/me.png'),
        lng_lat: '',
        area: {
          city: '',
          detailAddress: ''
        }
      }
    },
    methods: {
      // 选择后到诊室页面
      //返回上一级
      goBack() {
        this.$router.back();
        // this.id = this.$route.query.id;
        // this.doctorname = this.$route.query.doctorname;
        // if (this.$route.query.user == "doctor") {
        //   this.$router.push({
        //     name: 'selectClinic',
        //     query: {
        //       user: 'doctor',
        //     }
        //   });
        // } else if (this.$route.query.user == "order") {
        //   this.$router.push({
        //     name: 'medical_details',
        //     query: {
        //       doctorname: this.doctorname,
        //       id: this.id,
        //       status: this.$route.query.status,
        //     }
        //   });

        // }
      },
      // 判断入口
      init() {
          this.inputVal=this.$route.query.address;
        localStorage.setItem('status', JSON.stringify(this.$route.query.status))
        this.doctorname = this.$route.query.doctorname;
        this.id = this.$route.query.id;
        this.status = this.$route.query.status;
        if (this.$route.query.user) {
          this.user = this.$route.query.user;
        } else {
          this.user = "doctor";
        }
      },
      //显示清空的图标
      isShowX() {
        if (this.inputVal) {
          this.showX = true;
        } else {
          this.showX = false;
        }
      },
      //地图初始化
      initMap() {
        var _this = this;
        var map = new BMap.Map('allmap'); //创建map实例
        var point = new BMap.Point(108.91388, 34.240108);
        map.centerAndZoom(point, 18);
        // 百度地图API功能
        function G(id) {
          return document.getElementById(id);
        }
        function setPlace() {
          map.clearOverlays(); //清除地图上所有覆盖物
          function myFun() {
            var pp = local.getResults().getPoi(0).point; //获取第一个智能搜索的结果
            _this.lng_lat = JSON.stringify(pp);
            //矩形范围搜索
            map.centerAndZoom(pp, 18);
            var myIcon = new BMap.Icon(_this.iconImg, new BMap.Size(30, 30));
            var mk = new BMap.Marker(pp, {
              icon: myIcon
            });
            map.addOverlay(mk);
          }
          var local = new BMap.LocalSearch(map, { //智能搜索
            onSearchComplete: myFun
          });
          var myValue = _this.inputVal
          console.log(myValue)
          local.search(myValue);
        }
        setPlace()
        map.enableScrollWheelZoom(true); //启用滚轮放大缩小，默认禁用。
        map.enableDoubleClickZoom(true); //启用双击放大，默认启用。
        map.enablePinchToZoom(true); //启用双指操作缩放，默认启用。
      },
    },
    mounted() {
      //   this.getClinicList();
      this.initMap();
    },
    created() {
        this.init();

    }
  }

</script>
<style lang="scss" scoped>


</style>
